<?php

 header('Content-Type: text/html; charset=utf-8');
 
    // imagecreate (x width, y width)

	
	if(empty($_GET['color'])){
		$rgb_ = array(0=>255,1=>255,2=>255);
	}else{
		$rgb_ = html2rgb($_GET['color']);
	}
	
	if(empty($_GET['font'])){
		$font_size = 2;
	}else{
		$font_size = $_GET['font'];
	}
	
	
	$texto=	html_entity_decode( removeacentuacao(urldecode($_GET['text'])) );
	

	
	$tamanho_texto	=	strlen($texto)*ImageFontWidth($font_size)+10;
	
	
    $img_handle = @imagecreatetruecolor (15, $tamanho_texto) or die ("Cannot Create image"); 

    // ImageColorAllocate (image, red, green, blue)
	
	
	
	
	
	
	

    $back_color = ImageColorAllocate ($img_handle, $rgb_[0], $rgb_[1], $rgb_[2]); 

	Imagefill($img_handle, 0, 0, $back_color);

    $txt_color = ImageColorAllocate ($img_handle, 0, 0, 0); 

	//$font = imageloadfont("font/courier8.gdf");

	
	
	
	//ImageStringUp ($img_handle, imageloadfont("bubblebath.gdf"), 1, $tamanho_texto-6, $texto, $txt_color); 
	
    ImageStringUp ($img_handle, $font_size, 1, $tamanho_texto-6, $texto, $txt_color); 



	header ("Content-type: image/png"); //exit("bruno");
    ImagePng ($img_handle); 

    ImageDestroy($img_handle);


function removeacentuacao($text){
	
	$acentos = array(
        'À','Á','Ã','Â', 'à','á','ã','â',
        'Ê', 'É',
        'Í', 'í', 
        'Ó','Õ','Ô', 'ó', 'õ', 'ô',
        'Ú','Ü',
        'Ç', 'ç',
        'é','ê', 
        'ú','ü',
        );
    $remove_acentos = array(
        'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a',
        'e', 'e',
        'i', 'i',
        'o', 'o','o', 'o', 'o','o',
        'u', 'u',
        'c', 'c',
        'e', 'e',
        'u', 'u',
        );
    return str_replace($acentos, $remove_acentos, urldecode($text));

	
}	
	
function html2rgb($color)
{
    if ($color[0] == '#')
        $color = substr($color, 1);

    if (strlen($color) == 6)
        list($r, $g, $b) = array($color[0].$color[1],
                                 $color[2].$color[3],
                                 $color[4].$color[5]);
    elseif (strlen($color) == 3)
        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
    else
        return false;

    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);

    return array($r, $g, $b);
}

	
	
?>